package org.myy.learn.aaa.c_滑动窗口;

import lombok.extern.slf4j.Slf4j;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Set;

@Slf4j
public class 无重复字符的最长子串 {
    public static int lengthOfLongestSubstring(String s) {
        char[] strs = s.toCharArray();
        Set<Character> set = new HashSet<>();
        int longest = 0;
        for (int  left = 0, right = 0; right < strs.length; right++){
            while (set.contains(strs[right])){
                set.remove(strs[left]);
                left++;
            }
            set.add(strs[right]);
            longest = Math.max(longest, right-left+1);
        }
        return longest;
    }

    public static void main(String[] args) {
        String s = new String("abcabcbb");
        int lengthOfLongestSubstring = lengthOfLongestSubstring(s);
        log.info("执行结束, lengthOfLongestSubstring={}", lengthOfLongestSubstring);
    }
}
